﻿using System;
using Luna.Data;
using Luna.Data.Configuration;
using Luna.Data.CRM;
using Rhino.Mocks;

namespace Luna.Services.Test.Contacts
{
    public class ContactDataCreator : DataCreator
    {
        private const string DESCRIPTION = "Description";

        private const string NAME = "Name";

        public void Configure()
        {
        }

        public ICategoryData CreateCategoryData()
        {
            ICategoryData L_Return = MockRepository.GenerateMock<object, ICategoryData, IEquatable<object>>() as ICategoryData;
            LoadReferenceData(L_Return);

            L_Return.Stub(x => x.Name).PropertyBehavior();
            L_Return.Name = GetString(NAME);
            L_Return.Description = GetString(DESCRIPTION);

            /*L_Return.PK = Guid.NewGuid();

            L_Return.Stub(x => x.Equals(Arg<object>.Matches(a => CheckTrue(a, L_Return)))).Return(true);
            L_Return.Stub(x => x.Equals(Arg<object>.Matches(a => CheckFalse(a, L_Return)))).Return(false);*/

            return L_Return;
        }

        public void Setup(IDataContext P_Context)
        {
            P_Context.Stub(x => x.Create<ICategoryData>()).WhenCalled(x => x.ReturnValue = CreateCategoryData()).Return(CreateCategoryData());
        }

        private static bool CheckFalse(object a, IReferenceData res)
        {
            return !(a is IReferenceData) || (a is IReferenceData && ((IReferenceData)a).PK == res.PK);
        }

        private static bool CheckTrue(object a, IReferenceData res)
        {
            return (a is IReferenceData) && ((IReferenceData)a).PK == res.PK;
        }
    }
}